/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import dto.LoaiToaTau;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import util.ConnectToMySql;

 
public class LoaiToaTauDAO {
      public static List<LoaiToaTau> LayDSLoaiToaTau() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
         List<LoaiToaTau> listLoaiToaTau = new ArrayList<LoaiToaTau>();

        Connection conn = ConnectToMySql.getConnection();
        if (conn != null) {
            try {
                CallableStatement cs = conn.prepareCall("select * from LoaiToaTau");
                 ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                        LoaiToaTau s = new LoaiToaTau();
                        s.setMaloaitoatau(rs.getInt("maloaitoatau"));
                        s.setTenloaitoatau(rs.getString("tenloaitoatau")); 
                        listLoaiToaTau.add(s);
                    }
                }
            } catch (Exception ex) {
                System.out.println(ex);
                return null;
            }
        }

        return listLoaiToaTau;
    }
    
    public static LoaiToaTau LayThongTinLoaiToaTau(int maLoaiToaTau)throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
        LoaiToaTau loai = new  LoaiToaTau();

        Connection conn = ConnectToMySql.getConnection();
        if (conn != null) {
            try {
                CallableStatement cs = conn.prepareCall("select * from LoaiToaTau where maloaitoatau=?");
                cs.setInt(1, maLoaiToaTau);
                 ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                        LoaiToaTau s = new LoaiToaTau();
                        s.setMaloaitoatau(rs.getInt("maloaitoatau"));
                        s.setTenloaitoatau(rs.getString("tenloaitoatau")); 
                        loai= s;
                    }
                }
            } catch (Exception ex) {
                System.out.println(ex);
                return null;
            }
        }

        return loai;
    }
}
